package vn.aptech.scrumgroup.model;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import demo.axitdn.physic.Unit;

public class PersonModel extends AbstractBaseModel{
	private int startX; //point x of center body
	private int startY; //point y of center body
	private int width; //width of body
	private int height; //height of body and foot
	private boolean brilliant;
	
	public boolean getBrilliant(){
		return brilliant;
	}
	
	public void setBrilliant(boolean isBrilliant){
		brilliant = isBrilliant;
	}

	@Override
	public void onDraw(Canvas c) {
		// TODO Auto-generated method stub
		drawPerson(c);
	}

	@Override
	public void onUpdate(double t) {
		// TODO Auto-generated method stub
		
	}
	
	public PersonModel(int startX, int startY, int width, int height, int backColor, int foreColor){
		super(backColor, foreColor);
		this.startX = startX;
		this.startY = startY;
		this.width = width;
		this.height = height;
	}
	
	private void drawPerson(Canvas canvas){
		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		ColorMatrix cm = new ColorMatrix();
		int brightness = 120;
		if (getBrilliant()){ 
			cm.set(new float[]{1,0,0,0,brightness,
		    		0,1,0,0,brightness,
		    		0,0,1,0,brightness,
		    		0,0,0,1,0
		    		});
			paint.setColorFilter(new ColorMatrixColorFilter(cm));
		}else {
			paint.setColorFilter(null);
		}//end else
		
		//draw body
		paint.setStyle(Style.FILL);
		paint.setColor(backColor);
		
		Rect center = new Rect();		
		int leftRight = width / 2;
		int topBottom = height / 2;
		center.left = startX - leftRight;
		center.right = startX + leftRight;
		center.top = startY - topBottom;
		center.bottom = startY + topBottom;
		int widthBody = center.right - center.left;
		canvas.drawRect(center, paint);		
		
		//draw head
		float radius = ((widthBody)/2) * 0.8f;
		float radiusWrapper = radius + Unit.i;
		float Cx = startX;
		float Cy = center.top - radius;		
		canvas.drawCircle(Cx, Cy, radius, paint);
		
		//draw head wrapper
		paint.setColor(Color.WHITE);
		paint.setStyle(Style.STROKE);
		paint.setAntiAlias(true);
		canvas.drawCircle(Cx, Cy, radiusWrapper, paint);	
		
		//draw space between 2 foots
		//paint.setColor(Color.WHITE);
		paint.setAlpha(0);
		int spaceWidth = widthBody/10;
		if(spaceWidth == 0)
			spaceWidth = (int)Unit.i;
		Rect space = new Rect();
		space.left = (int)(startX - spaceWidth);
		space.right = (int)(startX + spaceWidth);
		space.top = startY;
		space.bottom = center.bottom;
		canvas.drawRect(space, paint);	
		
		//draw left hand
		//paint.setColor(Color.RED);
		paint.setAlpha(255);
		int handWidth = widthBody/3;
		if(handWidth == 0)
			handWidth = (int)Unit.i;
		Rect leftHand = new Rect();
		leftHand.right = (int)(center.left - Unit.i);
		leftHand.left = (int)(leftHand.right - handWidth);
		leftHand.top = center.top;
		leftHand.bottom = space.top;
		canvas.drawRect(leftHand, paint);	
		
		//draw right hand
		Rect rightHand = new Rect();
		rightHand.left = (int)(center.right + Unit.i);
		rightHand.right = (int)(rightHand.left + handWidth);
		rightHand.top = center.top;
		rightHand.bottom = space.top;
		canvas.drawRect(rightHand, paint);
	}


	@Override
	public boolean isPointOf(float x, float y) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void changeColor(int color) {
		// TODO Auto-generated method stub
		
	}

}
